/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.book;

import controllers.*;
import entity.Room;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import constants.Constants;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import controllers.MainController;
import demo.RoomI;
import javax.swing.*;
import javax.swing.table.TableModel;
/**
 *
 * @author Administrator
 */
public class GeneralInf extends javax.swing.JDialog {
  
    private boolean view;
    private boolean edit;
    private boolean checkin;
    private boolean add;
    private int id;
    private JTable table;
    private ArrayList<entity.Booking> list;
    public GeneralInf(JFrame parent, boolean modal,JTable table,boolean add,boolean checkin) {         
        super(parent, modal);
        init();
        this.table =table;
        this.add=add;
        this.checkin=checkin;
        initComponents();        
        this.setLocationRelativeTo(null);

    }
    public GeneralInf(JFrame parent,JTable table,boolean modal, boolean view,boolean checkin, int id){
            super(parent,modal);
            this.view=view;            
            this.checkin=checkin;
            this.id=id;
            this.table=table;
            init();
            initComponents();
            this.setLocationRelativeTo(null);
            this.setCustomer(list.get(0).getCustomer());
            this.setListRoom(BookingController.getRoomByCustomer(this.id)) ;
            this.setInfoBooking(list.get(0).getCustomer().getInfo());
            this.setAction();
    }
    public GeneralInf(JFrame parent,JTable table,boolean modal,int status,boolean edit, int id){
            super(parent,modal);
            this.edit=edit;
            this.id=id;
            this.table=table;
            this.status=status;
            init();
            initComponents();
            this.setLocationRelativeTo(null);
            this.setCustomer(list.get(0).getCustomer());
            this.setListRoom(BookingController.getRoomByCustomer(this.id)) ;
            this.setInfoBooking(list.get(0).getCustomer().getInfo());
            this.setAction();
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
     private void init(){
         MainController = new MainController();
         if(id>0) list= BookingController.getAllByCustomer(id);
         dlmRoom = new DefaultListModel();
         listRoom = new ArrayList<>();         
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jLabel1 = new javax.swing.JLabel();
        tfName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cbGender = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        tfAge = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfIdBooking = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfCard = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfNation = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tfPhone = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tfAddress = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        select = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        tfTip = new javax.swing.JTextField();
        tfCost = new javax.swing.JTextField();
        btBook = new javax.swing.JButton();
        done = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel21 = new javax.swing.JLabel();
        tfPay = new javax.swing.JTextField();
        java.util.Calendar cal = java.util.Calendar.getInstance();

        cal.add(java.util.Calendar.DATE, 1);
        tfDate2 = new com.toedter.calendar.JDateChooser();
        tfDate = new com.toedter.calendar.JDateChooser();
        tfTotal = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("THÔNG TIN ĐẶT PHÒNG");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel1.setText("Tên KH:");

        tfName.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel2.setText("Giới tính:");

        cbGender.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        cbGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nam", "Nữ" }));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel3.setText("Tuổi:");

        tfAge.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel4.setText("Mã DK:");

        tfIdBooking.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel5.setText("CMTND:");

        tfCard.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel6.setText("Quốc tịch:");

        tfNation.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel7.setText("Số điện thoại:");

        tfPhone.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel8.setText("Địa chỉ:");

        tfAddress.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel9.setText("Ngày đến:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel10.setText("Ngày đi:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel11.setText("(dd-mm-yyyy)");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel12.setText("(dd-mm-yyyy)");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel13.setText("Chọn phòng:");

        select.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        select.setText("...");
        select.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectActionPerformed(evt);
            }
        });

        jList2.setModel(this.dlmRoom);
        jList2.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList2ValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(jList2);

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel14.setText("Loại:");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel15.setText("Giá:");

        tfTip.setEditable(false);
        tfTip.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        tfTip.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        tfCost.setEditable(false);
        tfCost.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        tfCost.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        btBook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/checkin.png"))); // NOI18N
        btBook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBookActionPerformed(evt);
            }
        });

        done.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/close.png"))); // NOI18N
        done.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doneActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel17.setText("(VNĐ)");

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel18.setText("Đã thanh toán:");

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel19.setText("(VNĐ)");

        tfPay.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        tfPay.setText("0");
        tfPay.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                tfPayInputMethodTextChanged(evt);
            }
        });

        tfDate2.setDate(cal.getTime());
        tfDate2.setDateFormatString("dd - MM - yyyy");
        tfDate2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        tfDate.setDate(Calendar.getInstance().getTime());
        tfDate.setDateFormatString("dd - MM - yyyy");
        tfDate.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N

        tfTotal.setEditable(false);
        tfTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        tfTotal.setText("0");

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel20.setText("Tổng giá");

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel22.setText("(VNĐ)");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel9))
                                .addGap(16, 16, 16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(tfCard, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(28, 28, 28)
                                                .addComponent(jLabel2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(cbGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(34, 34, 34)
                                                .addComponent(jLabel3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(tfAge, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel4)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(tfIdBooking, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel6)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(tfNation, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel7)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(tfPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(0, 0, Short.MAX_VALUE))))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tfAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(tfDate, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel11)
                                        .addGap(54, 54, 54)
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(tfDate2, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(18, 18, 18)
                                .addComponent(select, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(35, 35, 35)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel14)
                                                .addComponent(jLabel15)
                                                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGap(18, 18, 18)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(tfTip, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                                                        .addComponent(tfCost))
                                                    .addGap(27, 27, 27)
                                                    .addComponent(jLabel19))
                                                .addGroup(layout.createSequentialGroup()
                                                    .addGap(3, 3, 3)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(tfTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                                                        .addComponent(tfPay))
                                                    .addGap(18, 18, 18)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel17)
                                                        .addComponent(jLabel22))))
                                            .addGap(45, 45, 45))
                                        .addComponent(jSeparator1))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(317, 317, 317)
                        .addComponent(btBook, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(done, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(cbGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(tfAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(tfIdBooking, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(tfNation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(tfPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addComponent(jLabel21)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(tfAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(tfDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tfDate2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel13)
                                .addComponent(select))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfTip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(tfCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19))
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(tfPay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(tfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel22))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(3, 3, 3)))
                        .addGap(10, 10, 10)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btBook, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(done, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void selectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectActionPerformed
         new RoomI(this, true,listRoom).setVisible(true);
    }//GEN-LAST:event_selectActionPerformed

    private void doneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneActionPerformed
                 this.dispose();
    }//GEN-LAST:event_doneActionPerformed

    private void btBookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBookActionPerformed
      if(this.validateForm()){
          if(add){
              this.add();
          }else{
              if(edit){
                this.edit();
              }else if(checkin){
                this.checkin();
              }
              
          }
       }  
      JOptionPane.showMessageDialog(null,Validate.message);
    }//GEN-LAST:event_btBookActionPerformed

    private void jList2ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList2ValueChanged
       if(!evt.getValueIsAdjusting()){
              System.out.println(jList2.getSelectedIndex());
              if(jList2.getSelectedIndex() > -1){
                this.setRoom(listRoom.get(jList2.getSelectedIndex()));
              }
       }
    }//GEN-LAST:event_jList2ValueChanged

    private void tfPayInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tfPayInputMethodTextChanged
      
    }//GEN-LAST:event_tfPayInputMethodTextChanged
    private void edit(){
         int choice = JOptionPane.showConfirmDialog(this,"Bạn muốn sửa ?", "Sửa",JOptionPane.YES_NO_OPTION);
            if(choice== JOptionPane.YES_OPTION){   
                  MainController.updateAll(this.getCustomer(),this.getInfoBooking(), listRoom);                 
               if(table!=null){
                   ((model.InfoBookingModel) table.getModel()).editList(table.getSelectedRow(),this.getInfoBooking());
                    updateTable();
               }                
                    this.dispose();
            }
    
    }
    private void checkin(){
     int choice = JOptionPane.showConfirmDialog(this,"Bạn muốn check in cho khách hàng này?", "Check in",JOptionPane.YES_NO_OPTION);
            if(choice == JOptionPane.YES_OPTION){
                   MainController.checkIn(id,this.getInfoBooking(),listRoom);
                   if(table!=null) {
                      ((model.InfoBookingModel) table.getModel()).removeRow(table.getSelectedRow());      
                      updateTable();
                   }
                   this.dispose();
            }
    
    }
    private void add(){
                int choice = JOptionPane.showConfirmDialog(this,"Bạn muốn thêm đăt phòng  ?", "Thêm",JOptionPane.YES_NO_OPTION);
                if(choice== JOptionPane.YES_OPTION){
                    id = MainController.addAll(this.getCustomer(),this.getInfoBooking(), listRoom);
                    if(checkin) RoomController.updateStatusInList(listRoom,Constants.CHECKIN);
                    if(id!=-1){                    
                        ((model.InfoBookingModel) table.getModel()).insertList(getInfoBooking());
                        updateTable();
                        this.dispose();
                    }else JOptionPane.showMessageDialog(this,"Thêm thông tin thất bại ");
                }           
                
    }
     private void setAction(){
                
                if(view||edit){
                 if(view)   {
                            btBook.setEnabled(false); 
                            select.setEnabled(false);
                            }
                }            
                if(checkin){                      
                        tfName.setEditable(false);
                        cbGender.setEnabled(false);
                        tfAge.setEditable(false);
                        tfNation.setEditable(false);
                        tfCard.setEditable(false);
                        tfPhone.setEditable(false);
                        tfAddress.setEditable(false);
                        select.setEnabled(false);
                        
                }
                switch(status){
                    case Constants.STATUS_BOOK:                         
                        break;
                    case Constants.STATUS_CHECKIN:
                        tfDate.setEnabled(false);
                        break;
                    case Constants.STATUS_CHECKOUT:    
                
                }
        }
        public entity.Customer getCustomer(){
            entity.Customer customer = new entity.Customer();
            customer.setId(id);
            customer.setName(tfName.getText());
            customer.setGender(cbGender.getSelectedIndex());
            customer.setAge(Integer.parseInt(tfAge.getText()));
            customer.setCountry(tfNation.getText());
            customer.setId_card(Integer.parseInt(tfCard.getText()));
            customer.setPhone(tfPhone.getText());
            customer.setAddress(tfAddress.getText());          
        return customer;
    }
        private void setCustomer(entity.Customer customer){          
            tfName.setText(customer.getName());
            cbGender.setSelectedIndex(customer.getGender());
            tfAge.setText( new Integer(customer.getAge()).toString());
            tfNation.setText(customer.getCountry());
            tfCard.setText(new Integer(customer.getId_card()).toString());
            tfPhone.setText(customer.getPhone());
            tfAddress.setText(customer.getAddress());
           
        }
        private void setInfoBooking(entity.InfoBooking info){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            tfDate.setDate(sdf.parse(info.getCheckin()));
            tfDate2.setDate(sdf.parse(info.getCheckout()));
        } catch (ParseException ex) {
            Logger.getLogger(GeneralInf.class.getName()).log(Level.SEVERE, null, ex);
        }
       tfPay.setText(new Integer(info.getPayment()).toString());
           tfTotal.setText(new Integer(info.getTotal()).toString()); 
        }
        private entity.InfoBooking getInfoBooking(){
            entity.InfoBooking info = new entity.InfoBooking();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            info.setCheckin(sdf.format(tfDate.getDate()));
            info.setCheckout(sdf.format(tfDate2.getDate()));
            info.setDate(sdf.format(new Date()));
            info.setTotal(MainController.totalCost(listRoom)); 
            info.setId_customer(id);            
            info.setNumber_room(listRoom.size());
            try{
            info.setPayment(Integer.parseInt(tfPay.getText()));
            }catch(NumberFormatException ex){
                info.setPayment(0);
            }
            info.setStatus(status);
            info.setCustomer(this.getCustomer());
            return info;
        }
        private void setRoom(entity.Room room){ 
            tfTip.setText(room.getRoomtype().getName());
            tfCost.setText(new Integer(room.getRoomtype().getCost()).toString());             
        }
        private void loadListRoom(){
            dlmRoom.removeAllElements();
            for(Room room : listRoom ){
                dlmRoom.addElement(room.getName());
            }
            if(listRoom.isEmpty()){
                tfTip.setText(null);
                tfCost.setText(null);
                tfPay.setText(null);
            }
        }

        public void setListRoom(ArrayList<Room> listRoom) {
            this.listRoom = listRoom;          
            this.loadListRoom();
        }

        public void loadView(int id){

        }
        public boolean validateForm(){
            if(!Validate.isAge(tfAge.getText())
                    ||!Validate.isCMT(tfCard.getText())
                    ||!Validate.isPhone(tfPhone.getText())
                    ||!Validate.isEmpty(tfName.getText())
                    ||!Validate.isEmpty(tfNation.getText())
                    ||!Validate.isEmpty(tfAddress.getText())
                    ||!Validate.isRoom(listRoom)
                    ){
                
                 return false;
            }
            if( ! isDate()){
                return false;
            }
            return true;
        }
        public void updateTable(){
            table.repaint();
            System.out.println("Cập nhật trên giao diện"); 
            
        }
        
    private String convertDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("dd - MM - yyyy");
        
        return sdf.format(date);
    }
    
    public boolean isDate(){
        Date den, di, now;
        now = new Date();
        den = tfDate.getDate();
        di = tfDate2.getDate();
          
        try{        
            if(now.before(den) || (den.getDay() == now.getDay())){

                long songay = between2Dates(den, di);
                System.out.println(" Số ngày đăng ký là: " + songay);
                if(songay == 0 ){
                    javax.swing.JOptionPane.showMessageDialog(this, "Ngày đi phải sau ngày đến!"); 
                    return false;
                 }
           }else{
                javax.swing.JOptionPane.showMessageDialog(this, "Ngày đến trước ngày đăng ký!");
                return false;
            }            
       }catch(NullPointerException ex){
                javax.swing.JOptionPane.showMessageDialog(this, "Sai dinh dang ngay !");
                return false;
            }
        return true;
    }
    public long between2Dates(Date dBefore, Date dAfter){
        long before = dBefore.getTime();
        long after = dAfter.getTime();

        if(after > before){
            long h = 24*3600000;
            return after/h - before/h;
        }
        return 0;
    }

    public void setTotalCost(int totalCost) {
       tfTotal.setText(new Integer(totalCost).toString()); 
    }
    public void displayMessage(){
      if(!Validate.message.equals(""))  JOptionPane.showMessageDialog(this,Validate.message);
        Validate.message="";
    }
    private MainController MainController;
    private ArrayList<Room> listRoom;
    private DefaultListModel dlmRoom;
    private int status;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btBook;
    private javax.swing.JComboBox cbGender;
    private javax.swing.JButton done;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton select;
    private javax.swing.JTextField tfAddress;
    private javax.swing.JTextField tfAge;
    private javax.swing.JTextField tfCard;
    private javax.swing.JTextField tfCost;
    private com.toedter.calendar.JDateChooser tfDate;
    private com.toedter.calendar.JDateChooser tfDate2;
    private javax.swing.JTextField tfIdBooking;
    private javax.swing.JTextField tfName;
    private javax.swing.JTextField tfNation;
    private javax.swing.JTextField tfPay;
    private javax.swing.JTextField tfPhone;
    private javax.swing.JTextField tfTip;
    private javax.swing.JTextField tfTotal;
    // End of variables declaration//GEN-END:variables
}
